package com.bkgy.sys.echartstable.controller;

import com.alibaba.fastjson.JSON;
import com.bkgy.sys.common.entity.JCommon;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.sys.echartstable.entity.Echartstable;
import com.bkgy.sys.echartstable.entity.JEchartstable;
import com.bkgy.sys.echartstable.service.EchartstableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
* echarts图控制器层
* @author  生成器生成
* @date 2019-08-21 17:28:32
*/
@RestController
@RequestMapping("/echartstable")
public class EchartstableController {

	@Autowired
	private EchartstableService echartstableService;
	
	/**
	 * 添加记录
	 * @param //userId 用户id
     * @param //sname 用户姓名
	 * */
	@CrossOrigin
	@RequestMapping(value={"/insert"}, method=RequestMethod.POST)
	@ResponseBody
	public ResultData insertDataEchartstable(@RequestBody String data,@RequestHeader(value="loginToken") String loginToken){
		JCommon common = JSON.parseObject(loginToken,JCommon.class);
    	String sname = common.getSname();
    	Long userId = common.getUserId();
		return echartstableService.insertDataEchartstable(data,userId, com.bkgy.util.CodiUtil.returnLm(sname));
	};
	
	/**
	 * 根据主键删除对象
	 * @param data json字符串
	 * */
	@CrossOrigin
	@RequestMapping(value={"/deleteOne"}, method=RequestMethod.POST)
	@ResponseBody
	public ResultData deleteDataEchartstableOne(@RequestBody String data){
		try{
    		JEchartstable jechartstable = JSON.parseObject(data,JEchartstable.class);
    		return echartstableService.deleteDataEchartstableOne(jechartstable.getIndocno());
    	}catch(Exception e){
    		e.printStackTrace();
    		return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null); 
    	}
	};
	
	/**
     * 根据主键字符串删除多个对象
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/deleteMany"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData deleteDataSysUserMany(@RequestBody String data) {
    	try{
    		JEchartstable jechartstable = JSON.parseObject(data,JEchartstable.class);
    		return echartstableService.deleteDataEchartstableMany(jechartstable.getStr_indocno());
    	}catch(Exception e){
    		e.printStackTrace();
    		return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null); 
    	}
    }
	
	/**
     * 修改记录
     * @param data json字符串
     * @param loginToken 请求头参数字符串对象
     */
    @CrossOrigin
	@RequestMapping(value={"/update"}, method=RequestMethod.POST)
	@ResponseBody
	public ResultData updateDataEchartstable(@RequestBody String data,@RequestHeader(value="loginToken") String loginToken){
		JCommon common = JSON.parseObject(loginToken,JCommon.class);
    	String sname = common.getSname();
    	Long userId = common.getUserId();
		return echartstableService.updateDataEchartstable(data,userId, com.bkgy.util.CodiUtil.returnLm(sname));
	};
	
	/**
     * 分页查看记录
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findByPage"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findDataEchartstableByPage(@RequestBody String data) {
        return echartstableService.findDataEchartstableByPage(data);
    }
    
    /**
     * 根据主键查询单条记录
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findByIndocno"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findDataEchartstableByIndocno(@RequestBody String data) {
        return echartstableService.findDataEchartstableByIndocno(data);
    }
	
	/**
	 * 查看记录
	 * @return list 对象集合返回
	 * */
	@CrossOrigin
	@RequestMapping(value={"/findAll"}, method=RequestMethod.POST)
	public List<Echartstable> findDataEchartstable(){
		return echartstableService.findDataEchartstable();
	};
}
